<template>
  <view class="reportList">
    <view
      class="reportItem"
      v-for="item in latestReportList"
      :key="item.id"
      @tap="goToItem(item.pageId)"
    >
      <view class="report-info">
        <view class="icon-file" />
        {{ item.title }}
        <text class="text">{{ item.formatCreateDate }}</text>
      </view>
    </view>
    <empty-tip v-if="list.length <= 0" />
  </view>
</template>

<script>
import Taro from "@tarojs/taro";
import * as repostService from "../../../services/report-service";
import "./index.less";
import EmptyTip from "../../../common-components/empty-tip/index.vue";

export default {
  components: {
    EmptyTip
  },
  data() {
    return {
      list: []
    };
  },
  computed: {
    xuetangList() {
      return this.list.filter(item => item.type === 'XUETANG');
    },
    xuezhiList() {
      return this.list.filter(item => item.type === 'XUEZHI');
    },
    latestReportList() {
      const latestReportList = [];
      if (this.xuetangList.length !== 0) {
        latestReportList.push(this.xuetangList[0]);
      }

      if (this.xuezhiList.length !== 0) {
        latestReportList.push(this.xuezhiList[0]);
      }
      return latestReportList;
    }
  },
  methods: {
    async getList() {
      let result = await repostService.getReportList();
      this.list = result.data.data;
      console.log(this.xuetangList, '======');
      console.log(this.xuezhiList, 'xuezhi=====');
    },
    goToItem(pageId) {
      Taro.navigateTo({
        url: `/pages/health-questionnaire/suggestion/index?pageId=${pageId}`
      });
    }
  },
  async created() {
    await this.getList();
  }
};
</script>
